package com.yf.activity.controller;


import com.yf.activity.controller.dto.UserAndCouponDTO;
import com.yf.activity.controller.dto.UserCouponPojo;
import com.yf.activity.domain.DrMemberFavourable;
import com.yf.activity.feign.UserFeignClient;
import com.yf.activity.feign.dto.DrUserDTO;
import com.yf.activity.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @Autowired
    private UserFeignClient userFeignClient;


    @RequestMapping(value = "user-coupon", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity getMemberFavourableByUid(
            @RequestParam(name = "uid") Integer uid) {

        UserAndCouponDTO userAndCouponDTO = new UserAndCouponDTO();

        List<DrMemberFavourable> memberFavourableList = activityService.getMemberFavourableByUid(uid);

        DrUserDTO userDTO = userFeignClient.findByUid(uid);
        if (userDTO != null) {
            userAndCouponDTO.setUid(userDTO.getUid());
            userAndCouponDTO.setRealName(userDTO.getRealName());
            userAndCouponDTO.setMobilePhone(userDTO.getMobilePhone());

            userAndCouponDTO.setCoupons(UserCouponPojo.transform(memberFavourableList));
        }


        return ResponseEntity.ok(userAndCouponDTO);
    }
}
